package day3;

import java.util.*;
public class Solution {
    public static int MoreThanHalfNum_Solution(int [] array) {
        Arrays.sort(array);
        int count=1;
        int k=(array.length+2)/2;
        for(int i=0;i<array.length-1;i++){
            if(array[i]==array[i+1]){
                count++;
                if(count>=k)
                    return array[i];
            }else{

                count=1;
            }

        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arr={3,3,3,3,3,2,2,2,2};
        System.out.println(MoreThanHalfNum_Solution(arr));
    }
}